<?php

namespace App\Http\Controllers\Live;

use App\Models\Lesson;
use App\Models\Student;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class LiveController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');

    }

    /**
     * @param Lesson $lesson
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function broadcast(Lesson $lesson){
        $room = $lesson->room_id;
        $auth = Auth::user();
        $signTime = time();
        $sign = \WeiHou::getSign([
            'roomid'=>$room,
            'account'=>$auth->mobile,
            'username'=> $auth->student->name,
            'signedat'=> $signTime
        ]);
        $classmate_count = Student::query()->where('school_id',$auth->student->school_id)->count();
        $classmate = Student::query()->where('school_id',$auth->student->school_id)->limit(8)->get();
        return view('live.broadcast',compact('lesson','room','signTime','sign','auth','classmate_count','classmate'));
    }

    /**
     * @param Lesson $lesson
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function play(Lesson $lesson){
        $room = $lesson->video_path;
        $auth = Auth::user();
        $signTime = time();
        $sign = \WeiHou::getSign([
            'roomid'=>$room,
            'account'=>$auth->mobile,
            'username'=> $auth->student->name,
            'signedat'=> $signTime
        ]);
        $classmate_count = Student::query()->where('school_id',$auth->student->school_id)->count();
        $classmate = Student::query()->where('school_id',$auth->student->school_id)->limit(8)->get();
        return view('live.play',compact('lesson','room','signTime','sign','auth','classmate_count','classmate'));
    }
}
